<?php
/**
 * Description
 *
 * PHP version 7
 *
 * @category Custom
 * @package  Custom
 * @author   ryu <mo5467@126.com>
 * @date     2020-04-28 23:49:14
 * @lastTime 2020-05-01 23:44:36
 * @license  https://opensource.org/licenses/MIT MIT License
 * @link     none
 */
namespace Test\Unit;

use Design\Behavioral\Observer\User;
use Design\Behavioral\Observer\UserObserver;

class ObserverTest extends \Test\BaseTest
{


    public function testObserver()
    {
        $observer = new UserObserver();
        $user     = new User();
        $reflection = new \ReflectionProperty($user, 'observers');

        $reflection->setAccessible(true);
        
        $observers = $reflection->getValue($user);
        $user->attach($observer);

        $user->changeEmail('123456@123.com');
        $this->assertCount(1, $observer->getChangedUsers());

        $user->detach($observer);
        $this->assertFalse($observers->contains($observer));

    }//end testObserver()


}//end class
